package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.Sport;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface SportMapper {

    //分页
    @Select("<script> SELECT * FROM t_sport\n" +
            "\n" +
            "            <if test=\"value !=null and value.length > 0\">\n" +
            "                where number LIKE concat('%',#{value},'%') or name like concat('%',#{value},'%')\n" +
            "            </if>\n" +
            "\n" +
            "    </script>")
    Page<Sport> findPage(String queryString);


    //添加
    @Insert("insert into t_sport\n" +
            "        values\n" +
            "        (null,#{number},#{name},#{exerciseRisk},#{kind},#{timeforexcercise},#{exercisefrequency},#{type},#{strength},#{MET}," +
            "#{thousandStepsEquivalent},#{thousandStepsEquivalent_time},#{minimumAge},#{maximumAge},#{actionSite},#{actionMethod},#{enable}," +
            "#{calories},#{energy},#{precautions},#{ageRange})")
    void add(Sport sport);

    //编辑窗口回显数据
    @Select(" select * from t_sport where id = #{id}")
    Sport findSportById(Integer id);

    //编辑
    @Update("<script> update t_sport\n" +
            "        <set>\n" +
            "            <if test=\"number !=null\">\n" +
            "                number = #{number},\n" +
            "            </if>\n" +
            "            <if test=\"name !=null\">\n" +
            "                name = #{name},\n" +
            "            </if>\n" +
            "            <if test=\"exerciseRisk !=null\">\n" +
            "                exerciseRisk = #{exerciseRisk},\n" +
            "            </if>\n" +
            "            <if test=\"kind !=null\">\n" +
            "                kind = #{kind},\n" +
            "            </if>\n" +
            "            <if test=\"timeforexcercise !=null\">\n" +
            "                timeforexcercise = #{timeforexcercise},\n" +
            "            </if>\n" +
            "            <if test=\"exercisefrequency !=null\">\n" +
            "                exercisefrequency = #{exercisefrequency},\n" +
            "            </if>\n" +
            "            <if test=\"type !=null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"strength !=null\">\n" +
            "                strength = #{strength},\n" +
            "            </if>\n" +
            "            <if test=\"MET !=null\">\n" +
            "                MET = #{MET},\n" +
            "            </if>\n" +
            "            <if test=\"thousandStepsEquivalent !=null\">\n" +
            "                thousandStepsEquivalent = #{thousandStepsEquivalent},\n" +
            "            </if>\n" +
            "            <if test=\"thousandStepsEquivalent_time !=null\">\n" +
            "                thousandStepsEquivalent_time = #{thousandStepsEquivalent_time},\n" +
            "            </if>\n" +
            "            <if test=\"minimumAge !=null\">\n" +
            "                minimumAge = #{minimumAge},\n" +
            "            </if>\n" +
            "            <if test=\"maximumAge !=null\">\n" +
            "                maximumAge = #{maximumAge},\n" +
            "            </if>\n" +
            "            <if test=\"actionSite !=null\">\n" +
            "                actionSite = #{actionSite},\n" +
            "            </if>\n" +
            "            <if test=\"actionMethod !=null\">\n" +
            "                actionMethod = #{actionMethod},\n" +
            "            </if>\n" +
            "            <if test=\"enable !=null\">\n" +
            "                enable = #{enable},\n" +
            "            </if>\n" +
            "            <if test=\"precautions !=null\">\n" +
            "                precautions = #{precautions},\n" +
            "            </if>\n" +
            "             <if test=\"ageRange !=null\">\n" +
            "                 ageRange = #{ageRange},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}</script>")
    void edit(Sport sport);


    //删除

    @Delete("DELETE FROM t_sport WHERE id = #{id}")
    void deleteById(Integer id);

}
